home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / MOUSE.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  5KB  |  253 lines

  1. #include "pt.h"
  2.  
  3. int pascal
  4. /* XTAG:isMouseEvent */
  5. isMouseEvent(doSimMouse)
  6.     int doSimMouse;
  7. {
  8.     extern int evhead, evtail;
  9.     static int n = 0;
  10.  
  11.     if( doSimMouse )
  12.         readSimMouse();
  13.     return evhead != evtail;
  14. }
  15.  
  16. int pascal
  17. /* XTAG:getMouseEvent */
  18. getMouseEvent()
  19. {
  20.     extern int evhead, evtail;
  21.     extern int debug;
  22.     extern struct event events[];
  23.     extern unsigned char msgBuffer[];
  24.     
  25.     if( ++evhead >= NEVENTS )
  26.         evhead = 0;
  27.     return evhead;
  28. }
  29.  
  30. void pascal
  31. /* XTAG:up2Buttons */
  32. up2Buttons(row, col)
  33.     int *row, *col;
  34. {
  35.     extern union REGS rin, rout;
  36.     extern struct event events[];
  37.     extern int mousePresent;
  38.     
  39.     register int evhead;
  40.     
  41.     while( 1 ) {
  42.         while( !isMouseEvent(1) ) {
  43.             if( mousePresent ) {
  44.                 rin.x.ax = 3;
  45.                 int86(51, &rin, &rout);
  46.                 if( rout.x.bx == 0 ) {
  47.                     *row = rout.x.dx>>3;
  48.                     *col = rout.x.cx>>3;
  49.                     goto allUp;
  50.                 }
  51.             }
  52.         }
  53.         evhead = getMouseEvent();
  54.         if( events[evhead].buttons == 0 )
  55.             break;
  56.     }
  57.     *row = events[evhead].vertical>>3;
  58.     *col = events[evhead].horizontal>>3;
  59. allUp:
  60.     ;
  61. }
  62.  
  63. int pascal
  64. /* XTAG:downButtons */
  65. downButtons(row, col)
  66.     int *row, *col;
  67. {
  68.     extern union REGS rin, rout;
  69.     extern int evhead, evtail;
  70.     extern struct event events[];
  71.     extern unsigned char lastIgnored;
  72.     
  73.     lastIgnored = 0;
  74.     while( 1 ) {
  75.         if( lastIgnored == '\033' )    /* an ESCape? */
  76.             return 1;
  77.         if( !isMouseEvent(1) )
  78.             continue;
  79.         evhead = getMouseEvent();
  80.         if( events[evhead].buttons != 0 )
  81.             break;
  82.     }
  83.     *row = events[evhead].vertical>>3;
  84.     *col = events[evhead].horizontal>>3;
  85.     return 0;
  86. }
  87.  
  88. void pascal
  89. /* XTAG:readSimMouse */
  90. readSimMouse()
  91. {
  92.     extern union REGS rin, rout;
  93.     extern unsigned char lastIgnored;
  94.  
  95.     int fn;
  96.     unsigned char key, scan;
  97.  
  98.     /* give user a chance to change things with a keystroke */
  99.     if( isKeystroke() != 0 ) {
  100.         key = getKeystroke(&scan);
  101.         lastIgnored = key;
  102.         fn = translateKey(key, scan);
  103.         cursor(fn, 0);
  104.     }
  105. }
  106.  
  107. extern long getvect(int);
  108. extern void evinit(void);
  109.  
  110. void pascal
  111. /* XTAG:initMouse */
  112. initMouse(row, column, videoReset)
  113.     int row, column, videoReset;
  114. {
  115.     extern unsigned char msgBuffer[];
  116.     extern union REGS rin, rout;
  117.     extern int mousePresent;
  118.     extern int mouseHorizontal, mouseVertical;
  119.     extern int i43lines;
  120.     extern int scrRows;
  121.     extern unsigned char saveVideoMode;
  122.     extern unsigned int dispMemory;
  123.     extern int debug;
  124.     extern int mouseSpeed;
  125.     extern int evhead, evtail;
  126.     extern struct event *evaddr, events[];
  127.  
  128.     int start, stop;
  129.  
  130. if( videoReset ) {
  131.     /* we need to set the video mode before 43 lines mode */
  132.     rin.h.ah = 0;
  133.     switch( saveVideoMode ) {
  134. #ifdef GENIUS66
  135.         case 8:  rin.h.al = 8; break;
  136. #endif
  137.         case 7:  rin.h.al = 7; break;
  138.         case 4:
  139.         case 3:  rin.h.al = 3; break;
  140.         default: rin.h.al = saveVideoMode; break;
  141.     }
  142.     int86(0x10, &rin, &rout);
  143.  
  144.     /* use the alt char set for 43 line mode */
  145.     rin.h.ah = 0x11;        /* 43 line mode */
  146.     if( i43lines ) {
  147.         scrRows = 43;
  148.         rin.h.al = 0x12;    /* 8x8 double-dot font */
  149.     } else {
  150.         scrRows = 25;
  151.         rin.h.al = 0x11;    /* 8x14 monochrome font */
  152.     }
  153.     rin.h.bl = 0x0;    /* use block 0 */
  154.     int86(0x10, &rin, &rout);
  155. #ifdef GENIUS66
  156.     /* special case of genius display */
  157.     if( saveVideoMode == 8 )
  158.         scrRows = 66;
  159. #endif
  160. }
  161.  
  162.     if( dispMemory == 0xB000 ) {    /* monochrome display */
  163.         start = 4;
  164.         stop = 9;
  165.     } else {
  166.         start = 2;
  167.         stop = 5;
  168. #ifdef GENIUS66
  169.         /* this is just a guess as to what it should be */
  170.         start = 3;
  171.         stop = 13;
  172. #endif
  173.     }
  174.  
  175.     if( getvect(51) == 0L ) {
  176.         mousePresent = 0;
  177.         /* set the hardware cursor */
  178.         setCType(start, stop);
  179.     } else {
  180.         /* reset the mouse */
  181.         rin.x.ax = 0;
  182.         int86(51, &rin, &rout);
  183.         if( rout.x.ax != 0xFFFF ) {
  184.             mousePresent = 0;
  185.             setCType(start, stop);
  186.         } else {
  187.             mousePresent = 1;
  188.             rin.x.ax = 10;
  189.             rin.x.bx = 1;    /* use hardware cursor */
  190.             rin.x.cx = start;
  191.             rin.x.dx = stop;
  192.             int86(51, &rin, &rout);
  193.         }
  194.     }
  195.  
  196.     if( mousePresent ) {
  197.  
  198.         /* call mouse driver to allow 200 or 350 lines */
  199.         rin.x.ax = 8;    /* set min/max vertical position */
  200.         rin.x.cx = 0;
  201.         rin.x.dx = (i43lines ? 342 : 192);
  202.             /* 350 - 8 (1 char position) */
  203.             /* any value above 343 allows the cursor to go off */
  204.             /* the bottom of the screen */
  205. #ifdef GENIUS66
  206.         /* special case of genius display */
  207.         if( saveVideoMode == 8 )
  208.             rin.x.dx = 975;
  209. #endif
  210.         int86(51, &rin, &rout);
  211.  
  212.         /* position mouse at row 5, col 10 */
  213.         rin.x.ax = 4;
  214.         rin.x.cx = 8*column;
  215.         rin.x.dx = 8*row;
  216.         int86(51, &rin, &rout);
  217.  
  218.         /*  set the mickey/pixel ratio */
  219.         rin.x.ax = 15;
  220.         /* horizontal: mouseSpeed mickeys/8 pixels */
  221.         rin.x.cx = mouseSpeed;
  222.         /* vertical: 2*mouseSpeed mickeys/8 pixels */
  223.         rin.x.dx = 2 * mouseSpeed;
  224.         int86(51, &rin, &rout);
  225.  
  226.         /* show the mouse cursor */
  227.         rin.x.ax = 1;
  228.         int86(51, &rin, &rout);
  229.         
  230.         /* initialize the mouse interrupt handler */
  231.         evhead = evtail = 0;
  232.         evaddr = &events[0];
  233.         evinit();
  234.     } else {
  235.         setCPos(row, column);
  236.         mouseHorizontal = 8*column;
  237.         mouseVertical = 8*row;
  238.     }
  239. }
  240.  
  241. void pascal
  242. /* XTAG:termMouse */
  243. termMouse()
  244. {
  245.     extern union REGS rin, rout;
  246.     extern int mousePresent;
  247.  
  248.     if( mousePresent ) {
  249.         rin.x.ax = 0;
  250.         int86(51, &rin, &rout);
  251.     }
  252. }
  253.